package jvm;

import java.sql.Time;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * JVM调优测试
 */
public class JvmOptimization {

    /**
     * -Xmn10M 堆年轻代的空间10M
     * 测试在qps=100,堆内存=512M的时候,不配置from区和配置from区会有什么样的差异
     * 默认参数= -XX:+PrintGCDetails -Xmx512M -Xms512M
     * 调优参数= -XX:+PrintGCDetails -Xmx512M -Xms512M -XX:NewRatio=1
     *
     * @param args
     */
    public static void main(String[] args) {
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Integer threadNum = 3;
        JvmOptimization jvmOptimization = new JvmOptimization();
        ExecutorService executorService = Executors.newFixedThreadPool(threadNum);
        while (true) {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (int i = 0; i < threadNum; i++) {
                executorService.submit(() -> jvmOptimization.createTableInfo());
            }
        }


    }

    /**
     * 创建表单
     */
    public void createTableInfo() {
        Map<Integer,byte[]> map = new HashMap<>();
        for (int i = 0; i < 30; i++) {
            byte[] bytes = new byte[1024 * 1024 * 1] ; // 50k
            map.put(i, bytes);
        }

        try {
            TimeUnit.MILLISECONDS.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }
}
